/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.hanze.web.ola;

import java.io.File;
import java.util.HashMap;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Luuk
 */
public class AcceptGiroProcessor extends TimerTask{
    
    public static void process(){
        File folder = new File("c://pdf//inbox");
        File[] listOfFiles = folder.listFiles();
        for(File f : listOfFiles){
            processFile(f);
        }
    }
    
    public static void processFile(File f){
        HashMap<String, String> data = new AcceptGiroFileReader(f).readFile();
        if(new AcceptGiroValidator(data).validate()){
            AcceptGiroTransformer transformer = new AcceptGiroTransformer(data);
            AcceptGiro ag=new AcceptGiro("C:\\pdf\\outbox", "C:\\pdf\\outbox");
            try {
                ag.createAcceptGiroPdf(transformer.reference, transformer.euro, transformer.cent, transformer.betalingskenmerk, data.get("rekeningnummer"), transformer.naam, transformer.adresPC, data.get("plaatsnaam"), data.get("rekeningnummernaar"), data.get("naamnaar"));
            } catch (Exception ex) {
                System.out.println("Exception while generating PDF:\n");
                ex.printStackTrace();
            }
            AcceptGiroFileRemover.removeFile(f);
        }else{
            System.out.println("File: " + f.getName() + " didn't validate.");
        }
    }

    @Override
    public void run() {
        process();
    }
}
